//
// Copyright (c) 2009 All Right Reserved
//
// vl
//
// 2018-12-01
// Contains ...
using LargoCommon.Interfaces;
using LargoCommon.Music;
using System.Windows.Media;
using System.Windows.Threading;
namespace LargoPanels.Editor
{
///
/// Line Space.
///
///
///
public partial class LineSpace : IEditorSpace
{
#region Fields
/// Delta Vertical Scroll.
public readonly int DeltaVerticalScroll = 5;
/// Delta Horizontal Scroll.
public readonly int DeltaHorizontalScroll = 5;
/// The left space.
protected readonly int LeftSpace = 50;
/// The top space.
protected readonly int TopSpace = 10;
/// The left margin.
protected readonly int LeftMargin = 2 * SeedSize.CurrentWidth;
/// The top margin.
protected readonly int TopMargin = 2 * SeedSize.CurrentHeight;
#endregion
#region Static Fields
///
/// The void handler
///
private static readonly VoidHandler Handler = () => { }; //// 2016/08
#endregion
/// Visual children.
private readonly VisualCollection children;
#region Constructors
/// Initializes a new instance of the class.
public LineSpace() {
this.ResetCells();
this.children = new VisualCollection(this) {
this.CreateDrawingVisual()
};
//// mysize, width, height));
//// this.VisualTextRenderingMode = TextRenderingMode.Grayscale;
//// this.Elements = new List();
}
#endregion
#region Delegates
///
/// Void Handler.
///
private delegate void VoidHandler();
#endregion
#region Public properties
///
/// Gets or sets the number of bars.
///
///
/// The number of bars.
///
public int NumberOfBars { get; set; }
/// Gets or sets the number of lines.
/// The total number of lines.
public int NumberOfLines { get; set; }
///
/// Gets or sets the content of the musical.
///
///
/// The content of the musical.
///
public IMusicalContent MusicalContent { get; set; }
///
/// Gets or sets a value indicating whether this instance is music editor.
///
///
/// true if this instance is music editor; otherwise, false.
///
public bool IsMusicEditor { get; set; }
///
/// Gets or sets the highlighted cell.
///
///
/// The highlighted cell.
///
public BaseCell SelectedCell { get; set; }
#endregion
#region Public properties - Music
/// Gets the get musical header.
/// The get musical header.
public MusicalHeader GetMusicalHeader {
get {
var header = MusicalHeader.GetDefaultMusicalHeader;
header.NumberOfBars = this.NumberOfBars;
header.Metric.MetricBeat = 6;
header.Tempo = 200;
return header;
}
}
#endregion
#region Public methods
///
/// Loads the lines.
///
/// The musical block.
public void LoadVoices(MusicalBlock musicalBlock) {
if (musicalBlock == null) {
return;
}
int voicesTopSpace = 0;
int voicesLeftSpace = 0;
int voicesTopMargin = 0;
int voiceIdx = 0;
int lineShiftMargin = 0;
foreach (var line in musicalBlock.ContentLines) {
if (line.Voices == null) {
continue;
}
lineShiftMargin += 5 * SeedSize.BasicMargin;
foreach (var voice in line.Voices) {
var cell = new VoiceCell(this, voice) {
LineIndex = line.LineIndex,
PenBrush = Brushes.Black,
ContentBrush = Brushes.WhiteSmoke,
Left = voicesLeftSpace,
Top = voicesTopSpace + voicesTopMargin + lineShiftMargin + (voiceIdx * SeedSize.CurrentHeight),
Width = (2 * SeedSize.CurrentWidth) - SeedSize.BasicMargin,
Height = SeedSize.CurrentHeight - SeedSize.BasicMargin,
Voice = voice
};
this.VoiceCells.Add(cell);
voiceIdx++;
}
}
}
///
/// Copies the paste.
///
/// The code.
public void CopyPaste(char code)
{
var c = this.SelectedCell;
var cell = c; //// as ContentCell;
if (cell != null)
{
var p = cell.Point;
if (p.BarNumber == 0)
{
return;
}
if (code == 'C')
{
cell.Copy();
}
if (code == 'V')
{
cell.Paste();
}
}
}
#endregion
#region Private static
///
/// Does the void events.
///
private static void DoVoidEvents() {
//// Stack Overflow Exception
try {
//// Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Background, new VoidHandler(() => { }));
Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.ApplicationIdle, Handler);
}
catch { //// StackOverflowException ex
//// return; //// !?!?!
}
}
#endregion
}
}